﻿using System.Linq;
using System.Reflection;

namespace IInject.Reflection
{
	public class Constructor : MethodWrapper
	{
		private ConstructorInfo _info;

		public Constructor(ConstructorInfo constructorInfo) : base(constructorInfo)
		{
			_info = constructorInfo;
		}

		public virtual object Invoke()
		{
			return Invoke(Parameters.Select(p => p.Value).ToArray());
		}

		public override object Invoke(object obj)
		{
			return Invoke();
		}

		public virtual object Invoke(params object[] paramValues)
		{
			if (!SetParameters(paramValues))
			{
				return null;
			}

			return _info.Invoke(paramValues);
		}

		public override object Invoke(object obj, params object[] paramValues)
		{
			return Invoke(paramValues);
		}
	}
}
